trigger ItemTrigger on Item__c (after delete) {
    if(Trigger.isAfter && Trigger.isDelete)
    {
       List<Item_Group__c> ItemGroups = [SELECT name,id,Total_Inventory__c FROM Item_Group__c LIMIT 50000 ];
       Map<Id,Item_Group__c> ItemGroupMap = new Map<Id,Item_Group__c>();
       Map<Id,User> UserMap = new Map<Id,User>();
       List<User> Users = [SELECT id,name,Email,CreatedById FROM User LIMIT 50000];
       List<Item_Group__c> TempItemGroups = new List<Item_Group__c>();
       if(ItemGroups!=null && Users != null)
       {
           for(Item_Group__c itemGroup : ItemGroups)
           {
               ItemGroupMap.put(itemGroup.id,itemGroup);
           }
           for(User usr : Users)
           {
                UserMap.put(usr.id,usr);
           }
       }
       for(Item__c itm : Trigger.old)
       {
           Item_Group__c tempItemGroup = ItemGroupMap.get(itm.Item_Group__c);
           tempItemGroup.Total_Inventory__c = tempItemGroup.Total_Inventory__c - 1;
           tempItemGroups.add(tempItemGroup);
           if(tempItemGroup.Total_Inventory__c<=1)
           {
               Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
               mail.setToAddresses(new String[] {UserMap.get(itm.CreatedById).Email});
               mail.setSubject('Item out of Stock');
               mail.setPlainTextBody('Item '+itm.Name+' Is out of Stock. Current Stock is '+tempItemGroup.Total_Inventory__c+'. Please order items.');
               Messaging.sendEmail(new Messaging.SingleEmailMessage[]{ mail });
           }
       }
       update tempItemGroups;
    }
}